﻿using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using BLL.CustomAttribute;
using BLL.Utility;
using DataAnnotationsExtensions;

namespace BLL.Model.User
{
    /// <summary>
    /// 用户信息
    /// </summary>
    public class UserInfo
    {
        public UserInfo()
        {
            RoleList = new List<RoleInfo>();
        }

        [Key, StringProperty]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

        [Display(Name = "姓名"), StringProperty]
        [StringLength(20), Required(AllowEmptyStrings = false)]
        public string UserName { get; set; }

        [Display(Name = "帐户名"), StringProperty]
        [StringLength(20), Required(AllowEmptyStrings = false)]
        public string AccountName { get; set; }

        [Display(Name = "密码")]
        [StringLength(200), Required(AllowEmptyStrings = false)]
        public string Password { get; set; }

        [Display(Name = "电子邮箱"), StringProperty]
        [Email(ErrorMessage = "电子邮箱格式不正确！"), StringLength(100), Required(AllowEmptyStrings = false)]
        public string Email { get; set; }

        [Display(Name = "联系电话"), StringProperty]
        [Numeric, StringLength(11), Required(AllowEmptyStrings = false)]
        public string Phone { get; set; }

        [Display(Name = "拥有角色")]
        public virtual IList<RoleInfo> RoleList { get; set; }

        [Display(Name = "管理员"), NotMapped]
        public bool IsAdmin { get; set; }

        public override string ToString()
        {
            return ModelHelper<UserInfo>.AutoCreateModelString(this);
        }

    }
}